package _18_剑指OfferII;

public class _018_剑指OfferII有效的回文 {

    public boolean isPalindrome(String s) {
        // 双指针比较，遇到其他字符跳过
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            if (!Character.isLetterOrDigit(s.charAt(left))) {
                left++;
            } else if (!Character.isLetterOrDigit(s.charAt(right))) {
                right--;
            } else {
                // 都为字符
                char char1 = Character.toLowerCase(s.charAt(left++));
                char char2 = Character.toLowerCase(s.charAt(right--));
                if (char1 != char2) return false;
            }
        }
        return true;
    }

}
